package com.cszjzx.member.service;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import com.cszjzx.member.dao.FieldDAO;
import com.cszjzx.member.dao.FieldDAOImpl;
import com.cszjzx.member.po.Field;

public class FieldServiceImpl implements FieldService{
	private FieldDAO fieldDao = null;
	public FieldServiceImpl(){
		try {
			fieldDao = new FieldDAOImpl();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public List<Field> getFieldList(){
		List<Field> fields = null;
		try {
			fields = fieldDao.findAll();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return fields;
	}
	
	public boolean add(Field d){
		try {
			fieldDao.add(d);
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}
	
	public boolean edit(Field d){
		try {
			fieldDao.update(d);
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}
	
	public void delete(Field d){
		try {
			fieldDao.delete(d.getName());
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
